<?php
namespace app\controllers;
use Yii;
use yii\rest\ActiveController;
use app\models\Data;
use app\models\DataSearch;

use yii\data\Pagination;
use yii\data\ActiveDataProvider;
use app\models\UserBackend;
class ReadController extends ActiveController
{
    public $modelClass = 'app\models\Data';

    
    public function actions()
    {
        $actions = parent::actions();
        unset( $actions['index']);
        return $actions;
    }
    public function actionFile(){
    
    }
    public function actionIndex()
    {
        $searchModel = new DataSearch();
        $params = Yii::$app->request->queryParams;
        $user_id = UserBackend::find()->select('id')->where(['username' => $params['username']])->scalar();

        $dataProvider = new ActiveDataProvider([
            'query' => Data::find()->where(['user_id' =>$user_id]),
            'pagination' => [
                'pageSize' => isset($params['size'])?$params['size']:15,
                'page' => isset($params['page'])?$params['page']:0,
            ],'sort' => [
                'defaultOrder' => [
                    'created_at' => SORT_DESC,            
                ]
        ],
        ]);

        return $dataProvider;
    }
}
